class postorder_and_inorder_creat_binary_tree {

    static class TreeNode{
        public int value;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(int value) {
            this.value = value;
        }
    }

    public int indexend;
    public TreeNode buildTree(int[] inorder, int[] postorder) {
        indexend=postorder.length-1;
        return buildTreeChild(inorder,0,inorder.length-1,postorder);
    }

    public TreeNode buildTreeChild(int[] inorder,int begin,int end,int[] postorder){
        if(begin>end) return null;
        int j=0;
        TreeNode root = new TreeNode(postorder[indexend]);
        for(j=begin;j<=end;j++){
            if(postorder[indexend]==inorder[j]) break;
        }
        indexend--;
        root.right=buildTreeChild(inorder,j+1,end,postorder);
        root.left=buildTreeChild(inorder,begin,j-1,postorder);
        return root;
    }
}